﻿@model PurchaseOrderInstallmentItem
@{
    int i = ViewBag.I;
    var m = Model;
    decimal ExcludeVatAmount = (m.BidderQuotation.RemainQty ?? 0) * (m.BidderQuotation.Price ?? 0);
} 
<div class="Example_Q clearfix">
    <table border="0" style="width: 99%" cellpadding="0" cellspacing="1px">
        <tr>
            <td class="caption1">
                สินค้า/บริการ
            </td>
            <td colspan="100%" class="controls-detail">
                <strong>
                    @(Model.BidderQuotation.PurchaseRequestItem.ResItemId != null ? @Model.BidderQuotation.PurchaseRequestItem.MasResourceItem.Name : Model.BidderQuotation.PurchaseRequestItem.MasBudgetExpense.Name)
                </strong>
                @(string.IsNullOrWhiteSpace(Model.Descr) ? "" : " - " + Model.Descr)
                <span style="float: right">@(i++) / @(ViewBag.Count)</span>
            </td>
        </tr>

        <tr>
            <td class="caption1">
                จำนวนที่สั่ง
            </td>
            <td class="controls-detail">
                @Html.DisplayFor(model => m.Qty) @Html.DisplayFor(model => m.BidderQuotation.PurchaseRequestItem.MasResourceItem.MasUnit.Name)
            </td>
            <td class="caption1">
                เหลือยังไม่ตรวจรับ
            </td>
            <td class="controls-detail">
                @Html.DisplayFor(model => m.BidderQuotation.RemainQty) @Html.DisplayFor(model => m.BidderQuotation.PurchaseRequestItem.MasResourceItem.MasUnit.Name)
            </td>
            <td class="caption1">จำนวนเงินคงเหลือ	</td>
            <td class="controls-detail">@Html.DisplayFor(model => m.BidderQuotation.RemainAmount) บาท</td>
        </tr>

        <tr>
            <td class="caption1">จำนวนที่รับในงวด</td>
            <td class="controls-detail">@Html.TextBox("Qty_" + m.PoInstallItemId, m.BidderQuotation.RemainQty,
new { @class = "aSpinEdit2", data_placeholder = "จำนวนที่รับ", step = "any", min = 0, id = "Qty_" + m.PoInstallItemId })</td>
            <td class="caption1">ราคาต่อหน่วย</td>
            <td class="controls-detail">@Html.TextBox("Price_" + m.PoInstallItemId, m.BidderQuotation.Price,
new { @class = "aSpinEdit", data_placeholder = "ราคาต่อหน่วยไม่รวม Vat", step = "any", min = 0, id = "Price_" + m.PoInstallItemId })</td>
            <td class="caption1">ราคาไม่รวม Vat</td>
            <td class="controls-detail">@Html.TextBox("ExcludeVatAmount_" + m.PoInstallItemId, ExcludeVatAmount, 
            new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0,
                  max = m.ExcludeVatAmount,
                  id = "ExcludeVatAmount_" + m.PoInstallItemId
            })</td>
        </tr>
        <tr>
            <td class="caption1">% ส่วนลด</td>
            <td class="controls-detail">@Html.TextBox("DiscountPercent_" + m.PoInstallItemId, m.DiscountPercent,
new { @class = "aSpinEdit", data_placeholder = "% ส่วนลด", step = "any", min = 0, id = "DiscountPercent_" + m.PoInstallItemId })</td>
            <td class="caption1">ส่วนลดพิเศษ</td>
            <td class="controls-detail">@Html.TextBox("ExtraDiscount_" + m.PoInstallItemId, m.ExtraDiscount,
new { @class = "aSpinEdit", data_placeholder = "ส่วนลดพิเศษ", step = "any", min = 0, id = "ExtraDiscount_" + m.PoInstallItemId })</td>
            <td class="caption1">% Vat</td>
            <td class="controls-detail">@Html.TextBox("VatPercent_" + m.PoInstallItemId, 7,
new { @class = "aSpinEdit", data_placeholder = "% Vat", step = "any", min = 0, max = 100, id = "VatPercent_" + m.PoInstallItemId })</td>
        </tr>
        @{
            ExcludeVatAmount = ExcludeVatAmount - (ExcludeVatAmount * (decimal)(m.DiscountPercent ?? 0) / 100) - (decimal)(m.ExtraDiscount ?? 0);
            var VatAmount = ExcludeVatAmount * 7 / 100;
        }
        <tr>
            <td class="caption1">Vat (บาท)</td>
            <td class="controls-detail">@Html.TextBox("VatAmount_" + m.PoInstallItemId, VatAmount,
new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, max = m.ExcludeVatAmount, id = "VatAmount_" + m.PoInstallItemId })</td>
            <td class="caption1">ราคาสุทธิ</td>
            <td class="controls-detail">@Html.TextBox("NetAmount_" + m.PoInstallItemId, ExcludeVatAmount + VatAmount,
new { @class = "aSpinEdit", data_placeholder = "จำนวนเงินไม่รวม Vat", step = "any", min = 0, id = "NetAmount_" + m.PoInstallItemId })</td>
            <td>
                <img src="~/Content/Images/Icon/cal_icon.png" title="คลิกเพื่อคำนวน"
                     style="cursor: pointer" id="calculateIcon_@m.PoInstallItemId" />
            </td>
        </tr>

    </table>
</div>  